<script type="text/javascript">     

var loading_queue = 0;	// keep track of how many parts are loading
$(document).ready(function(){

    // setup ul.tabs to work as tabs for each div.pane
    $("ul.tabs").tabs("div.pane"); 

    // check for first change in form
    <? if($this->input->post("submit_action")!==FALSE){ ?>
        var hasChanged = true;                 
    <? } else { ?>
        var hasChanged = false;                
        $("input:submit").addClass("disabled");
    <? } ?>
    $("input,textarea,select").live("change", function(){
        if(hasChanged == false){
            hasChanged = true;
            $("input:submit").removeClass("disabled");
        }
    });

    $('#product_form').submit(function(e) {
		// check if all the content is loaded
		if (loading_queue>0){
			e.preventDefault();	
			console.log("can't save now, waiting for everything to load");
		}
	
		// for debuggin, can be deleted:			
		//var dataArray = $("#product_form").serializeArray();
		//len = dataArray.length;
		//for (i=0; i<len; i++) {
		//  console.log(dataArray[i].name+": "+dataArray[i].value);
		//}
		//if (!confirm("save?")){
		//	e.preventDefault();	
		//}	
		
	});
	
    //cancel button
    $(".cancel").click(function(){
        if (hasChanged != false)
            if (!confirm("If you leave this page now, you will loose the changes you've just made.\n\nProceed anyway?\n")) return false;
            window.location.href='<?=site_url("admin/products")?>';
        return false;
    });

});

function SetCheckboxClass(e){

    if ($(e).is(':checked')) {
        $(e).parent().removeClass('unchecked');
        $(e).parent().addClass('checked');
    } else {
        $(e).parent().addClass('unchecked');
        $(e).parent().removeClass('checked');
    }

}

</script>



<div id="content">      

<? if($this->input->post("submit_action") !== FALSE){ ?>
    <div class="response"><?=validation_errors()?></div>                
<? } ?>

    <form action="<? if ($this->uri->segment(3)=="copy"){ echo site_url("admin/products/add"); } ?>" method="post" id="product_form">                                                 

    <div class="float_block_right">
        <a href="#" class="button cancel">CANCEL</a>
        <a href="<?=site_url('admin/products/preview')?>" class="button" rel="preview">PREVIEW</a>
        <input type="submit" class="button " value="SAVE CHANGES">  
    </div>


    <? if ($action=='update') { ?>
        <h1>Edit product <i><?=$item["Name_Products"]?></i></h1>
    <? } else { ?>
        <h1>Add New Product</h1>
    <? } ?>


    <!-- the tabs --> 
    <ul class="tabs"> 
        <li><a href="#">About the product</a></li>        
        <li><a href="#">Images</a></li>        
        <li><a href="#">Specifications</a></li> 
        <li><a href="#">Applications</a></li> 
        <li><a href="#">Finishes</a></li> 
        <li><a href="#">About the supplier</a></li>     
    </ul> 
     
                                                         
    <div class="pane">                         
    <? $this->load->view('admin/products/pane_product_info'); ?>
    </div>                                                      

    <div class="pane">                         
    <? $this->load->view('admin/products/pane_product_images'); ?>
    </div> 

    <div class="pane">                         
    <? $this->load->view('admin/products/pane_product_specs'); ?>
    </div> 

    <div class="pane">                         
    <? $this->load->view('admin/products/pane_product_apps'); ?>
    </div> 
                                          
    <div class="pane">                         
    <? $this->load->view('admin/products/pane_product_finishes'); ?>
    </div> 

    <div class="pane">                         
    <? $this->load->view('admin/products/pane_product_supplier'); ?>   
    </div> 


               
    <input type="hidden" name="submit_action" value="<?=$action?>" />
    <input type="hidden" name="id" value="<?=$item['id_Products']?>" />
    <input type="hidden" name="token" value="<?=$token?>" /> 

    <div class="float_block_right">
        <a href="#" class="button cancel">CANCEL</a>
        <a href="<?=site_url('admin/products/preview')?>" class="button" rel="preview">PREVIEW</a>
        <input type="submit" class="button " value="SAVE CHANGES">  
    </div>

    </form>

</div>